<?php
/**
 * 权益
 * User: Acer
 * Date: 2022/7/10
 * Time: 1:13
 */
namespace app\move\controller;

use app\core\MyController as MyController;
use app\move\service\CardUserService;
use app\move\service\EquityService;

class Equity extends MyController
{
    protected $noNeedAction = []; // 不需要校验控制器，通道
    // 操作前置
    protected $beforeActionList = ['my_initialize'];

    // 操作前置方法
    public function my_initialize()
    {
    }
    // 权益卡片产品列表
    public function get_list(){
        $data = input();
        // 页数
        if(!isset($data['page']) || !isset($data['type']))  json_err( -201);
        // 当前页数
        if(!isset($data['page_number'])) $data['page_number'] = 10;
        // 查看卡片类型
        if(!isset($data['master'])) $data['master'] = 1;
        // 查询
        $like =[];
        // 卡片名称
        if( isset($data['name']) && $data['name'] ) {
            $like = [
                'name'=>$data['name']
            ];
        }
        $uid = $this->userId;
        if($data['master'] == 1){
            // 主卡
            $res = (new EquityService())->s_get_list($data['page'],$data['page_number'] > 0 ? $data['page_number'] : 1,$like,$uid, $data['type'] ? $data['type'] :2);
        }else if($data['master'] == 3){
            //代激活卡
            $res = (new EquityService())->s_agent_get_list($data['page'],$data['page_number'] > 0 ? $data['page_number'] : 1,$like,$uid, $data['type'] ? $data['type'] :2);
        }else{
            // 成员卡
            $res = (new EquityService())->s_fit_get_list($data['page'],$data['page_number'] > 0 ? $data['page_number'] : 1,$like,$uid, $data['type'] ? $data['type'] :2);
        }
        if($res) _action_result(200,$res,'操作成功！');
        json_err( -205);
    }
    // 卡片产品权益详情
    public function card_pro_info(){
        $data = input();
        if(empty($data['pid'])) json_err(-201);
        $res = (new EquityService())->s_card_pro_info($data['pid'],$this->userId);
        if($res) _action_result(200,$res,'操作成功！');
        json_err( -205);
    }

    // 失效权益卡列表
    public function invalid_card_list(){
        $data = input();
        // 页数
        if(!isset($data['page']))  json_err( -201);
        // 当前页数
        if(!isset($data['page_number'])) $data['page_number'] = 10;
//        // 查看卡片类型
        $arr = [1,2,3,4,5,6]; // 家庭关系（1：父母、2：子女、3：配偶、4：其他、5：儿子、6：女儿）
        $uid = $this->userId;
        $EquityService = new EquityService();
        if(!empty($data['type']) ){  // 家庭关系（1：父母、2：子女、3：配偶、4：其他、5：儿子、6：女儿）
            if(!in_array((int)$data['type'],$arr)) json_err(-201,['类型不存在！']);
            $EquityService->s_myself_family_invalid_card_list($data['page'],$data['page_number'] > 0 ? $data['page_number'] : 1,$uid,$data['type']);
        }else{
            // 本人
            $EquityService->s_myself_invalid_card_list($data['page'],$data['page_number'] > 0 ? $data['page_number'] : 1,$uid);
        }
    }

    // 阅读权益告知条款并提交签名
    public function read_card_rights() {
        $data = input();
        if(!isset($data['cu_id']) || !isset($data['img'])) json_err( -201);
        $res = (new EquityService())->read_card_rights($data['cu_id'],$this->userId,$data['img']);
        if($res) _action_result(200,[],'操作成功！');
        json_err( -205);
    }

    // 使用权益并填写资料
    public function apply_equity_info() {
        $data = input();
        if(empty($data['eid']) || empty($data['cu_id'])
            || empty($data['name']) || empty($data['id_card']) || empty($data['mobile']) || empty($data['remarks'])){
            json_err( -201);
        }
        $data['uid'] = $this->userId;
        $res = (new EquityService())->apply_equity_info($data);
        if($res) _action_result(200,[],'操作成功！');
        json_err( -205);
    }

    // 服务列表，权益申请列表
    public function get_apply_equity_info() {
        $data = input();
        $data['uid'] = $this->userId;
        $res = (new EquityService())->get_apply_equity_info($data);
        if($res) _action_result(200,$res,'操作成功！');
        _action_result(200,[],'操作成功！');
    }

    // 服务详情
    public function get_apply_equity_info_detail() {
        $data = input();
        if(empty($data['ue_id'])){
            json_err( -201);
        }
        $data['uid'] = $this->userId;
        $res = (new EquityService())->get_apply_equity_info_detail($data);
        if($res) _action_result(200,$res,'操作成功！');
        _action_result(200,[],'操作成功！');
    }

    // 获取省市区
    public function get_area_region() {
        $data = input();
        if(!isset($data['p_r_id'])||strlen($data['p_r_id'])==0){
            $data['p_r_id'] = 0;
        }
        if(!isset($data['level'])||strlen($data['level'])==0){
            $data['level'] = 1;
        }
        $data['uid'] = $this->userId;
        $res = (new EquityService())->get_area_region($data['p_r_id'],$data['level']);
        _action_result(200,$res,'操作成功！');
    }

    // 获取医院
    public function hospital(){
        $data = input();
        if(!isset($data['page'])||empty($data['page'])) $data['page'] = 1;
        if(!isset($data['page_number'])||empty($data['page_number'])) $data['page_number'] = 10;
        if(!isset($data['search'])||empty($data['search'])) $data['search'] = '';
        $res = (new EquityService())->hospital($data);
        _action_result(200,$res,'操作成功！');
    }

    // 权益物流列表
    public function get_apply_equity_express() {
        $data = input();
        $data['uid'] = $this->userId;
        $res = (new EquityService())->get_apply_equity_express($data);
        if($res) _action_result(200,$res,'操作成功！');
        _action_result(200,[],'操作成功！');
    }

    // 权益物流详情
    public function get_apply_equity_express_detail() {
        $data = input();
        if(empty($data['ue_id'])){
            json_err( -201);
        }
        $data['uid'] = $this->userId;
        $res = (new EquityService())->get_apply_equity_express_detail($data);
        if($res) _action_result(200,$res,'操作成功！');
        _action_result(200,[],'操作成功！');
    }
}
